#include<bits/stdc++.h>
using namespace std;
struct student
{
	string name;
	int a,b,c,sum;
	bool operator < (const student & x) const
	{
		return x.name>name;
	}
}s[1001];
int main()
{
	int i,n,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>s[i].name>>s[i].a>>s[i].b>>s[i].c;
		s[i].sum=s[i].a+s[i].b+s[i].c;
	}
	sort(s+1,s+i);
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++) 
		{
			if(abs(s[i].a-s[j].a)<=5 && abs(s[i].b-s[j].b)<=5 &&
			abs(s[i].c-s[j].c)<=5 && abs(s[i].sum-s[j].sum)<=10)
				cout<<s[i].name<<" "<<s[j].name<<endl;
		}
	}
    return 0;
}
